﻿$(document).ready(function() {
    $("#newGoalName").val("");

    $('#addGoal').click(function () {
        $('#goalPop, #overlay').fadeIn(1000);
    });

    $('.closeGoalPop').click(function () {
        $('.smallPop, #overlay').fadeOut(1000);
        $("#newGoalName").css({ 'background': 'url("../Resources/img/main/input.png") no-repeat' });
    });

    $('#closeTaskPop').click(function () {
        $('#addTaskPopUp, #overlay').fadeOut(1000);
    });

    $('.dropDownGoal').click(function () {
        var thisId = this.id.toString().substr(this.id.toString().length - 1);
        var selector = $('#dropDownGoalVal' + thisId);
        if (selector.css('display') == 'none') {
            selector.show();
        } else {
            $('.dropDownGoalVal').hide();
        }
    });

    $(".changeStatus").click(function() {
        __doPostBack('changeStatus', $("#taskIdField").text());
    });
});

function __doPostBack(eventTarget, eventArgument) {
    $('#__EVENTTARGET').val(eventTarget);
    $('#__EVENTARGUMENT').val(eventArgument);
    document.Form1.submit();
}


function showExceptionPop(message) {
    if (main) {
        hideTables();
    }
    alert(message);
}

function addNewTask(goalName) {
    var descr = $('#newTAskDescription');
    var taskName = $('#newTaskName');
    descr.val("");
    taskName.val("");
    descr.css({ 'background': 'url("../Resources/img/main/contactus-description-field.png") no-repeat' });
    taskName.css({ 'background': 'url("../Resources/img/main/input.png") no-repeat' });
    $("#goalNameTask").val(goalName);
    $('#addTaskPopUp, #overlay').fadeIn(1000);
}

function showDescription(description, taskId, status) {
    $('.description').text(description);
    $('#descriptionPop, #overlay').fadeIn(1000);
    $('.status').text(status);
    $("#taskIdField").text(taskId);
    if (status == "Ready") {
        $('.status').css({ 'color': 'blue' });
    }
}

function validateGoal() {
    var regex = new RegExp("^ +$");
    var selector = $("#newGoalName");
    if (selector.val() == "undefined" || selector.val() == "" || selector.val().length < 2 || regex.test(selector.val())) {
        selector.css({ 'background': 'url("../Resources/img/main/inputErr.png") no-repeat' });
        return false;
    }
    selector.css({ 'background': 'url("../Resources/img/main/input.png") no-repeat' });
    return true;
}

function validateTask() {
    var flag = true;
    var taskName = $('#newTaskName');
    var desr = $('#newTAskDescription');
    var regex = new RegExp("^ +$");
    if (taskName.val() == "" || regex.test(taskName.val())) {
        taskName.css({ 'background': 'url("../Resources/img/main/inputErr.png") no-repeat' });
        flag = false;
    } else {
        taskName.css({ 'background': 'url("../Resources/img/main/input.png") no-repeat' });
    }
    if (desr.val() == "" || regex.test(desr.val())) {
        desr.css({ 'background': 'url("../Resources/img/main/contactus-field-desc-empty.png") no-repeat' });
        flag = false;
    } else {
        desr.css({ 'background': 'url("../Resources/img/main/contactus-description-field.png") no-repeat' });
    }
    return flag;
}